package cn.com.homeyoda.aimate.aihealth.ui.record.blood_pressure;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import cn.com.homeyoda.aimate.aihealth.R;
import cn.com.homeyoda.aimate.aihealth.bean.BloodPressureBean;

public class BloodPressureRecordAdapter extends BaseQuickAdapter<BloodPressureBean.DataBean, BaseViewHolder> {

    public BloodPressureRecordAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, BloodPressureBean.DataBean item) {
        int color = ContextCompat.getColor(mContext, helper.getLayoutPosition() % 2 == 0 ? R.color.clr_0065FF_6 : R.color.clr_0065FF_2);

        helper.setBackgroundColor(R.id.tv_blood_pressure_time, color);
        helper.setBackgroundColor(R.id.tv_blood_pressure_low, color);
        helper.setBackgroundColor(R.id.tv_blood_pressure_high, color);

        helper.setText(R.id.tv_blood_pressure_time, item.getAddTime());

        int systolic = item.getSystolicPressure();
        int diastolic = item.getDiastolicPressure();
        helper.setText(R.id.tv_blood_pressure_low, String.valueOf(systolic));
        helper.setText(R.id.tv_blood_pressure_high, String.valueOf(diastolic));

        int systolicColor;
        if (systolic <= item.getSystolicValueMin()) {
            systolicColor = R.color.clr_2CB176;
        } else if (systolic >= item.getSystolicValueMax()) {
            systolicColor = R.color.clr_FF3333;
        } else {
            systolicColor = R.color.black_80;
        }
        helper.setTextColor(R.id.tv_blood_pressure_low, ContextCompat.getColor(mContext, systolicColor));

        int diastolicColor;
        if (diastolic <= item.getDiastolicValueMin()) {
            diastolicColor = R.color.clr_2CB176;
        } else if (diastolic >= item.getDiastolicValueMax()) {
            diastolicColor = R.color.clr_FF3333;
        } else {
            diastolicColor = R.color.black_80;
        }
        helper.setTextColor(R.id.tv_blood_pressure_high, ContextCompat.getColor(mContext, diastolicColor));
    }

    @Override
    public void setNewData(@Nullable List<BloodPressureBean.DataBean> data) {
        super.setNewData(data);
    }
}
